package com.jspgou.core.entity;

import com.jspgou.cms.entity.Role;
import com.jspgou.core.entity.base.BaseAdmin;
import java.util.Date;
import java.util.Set;

public class Admin extends BaseAdmin{
    private static final long serialVersionUID = 1L;
    
    public void init(){
        if(getCreateTime() == null)
            setCreateTime(new Date());
        if(getDisabled() == null)
            setDisabled(Boolean.valueOf(false));
    }
    
	/* [CONSTRUCTOR MARKER BEGIN] */
    public Admin(){
    	super();
    }
	/**
	 * Constructor for primary key
	 */
    public Admin(Long id){
        super(id);
    }

	/**
	 * Constructor for required fields
	 */
    public Admin(Long id,
    		User user, 
    		Website website, 
    		Date date, 
    		Boolean boolean1){
        super(id, 
        	  user, 
        	  website, 
        	  date, 
        	  boolean1);
    }
    
	/* [CONSTRUCTOR MARKER END] */

    public String getUsername(){
        User user = getUser();
        if(user != null){
            return user.getUsername();
        }else{
            return null;
        }
    }

    public String getEmail(){
        User user = getUser();
        if(user != null){
            return user.getEmail();
        }else{
            return null;
        }
    }

    public String getLastLoginIp()
    {
        User user = getUser();
        if(user != null)
            return user.getLastLoginIp();
        else
            return null;
    }

    public Date getLastLoginTime(){
        User user = getUser();
        if(user != null){
            return user.getLastLoginTime();
        }else{
            return null;
        }
    }

    public String getCurrentLoginIp(){
        User user = getUser();
        if(user != null){
            return user.getCurrentLoginIp();
        }else{
            return null;
        }
    }

    public Date getCurrentLoginTime(){
        User user = getUser();
        if(user != null){
            return user.getCurrentLoginTime();
        }else{
            return null;
        }
    }
    
    //*角色管理功能
    public Long[] getRoleIds() {
		Set<Role> roles = getRoles();
		return Role.fetchIds(roles);
	}
}
